package org.flashIso.engine.core {
	/**
	 * Point2D represents a point in a 2D space.
	 */
	public class Point2D extends ValidateableObject {
		private var _x : Number;
		private var _y : Number;

		public function Point2D(x : Number = 0, y : Number = 0) {
			super();
			this._x = x;
			this._y = y;
		}

		public function set x(value : Number) : void {
			if (_x != value) {
				_x = value;
				triggerValidation();
			}
		}

		public function get x() : Number {
			return _x;
		}

		public function set y(value : Number) : void {
			if (_y != value) {
				_y = value;
				triggerValidation();
			}
		}

		public function get y() : Number {
			return _y;
		}

		public function equals(p : Point2D) : Boolean {
			return (x == p.x && y == p.y);
		}

		public function distanceFrom(p : Point2D) : Number {
			var dx : Number = _x - p.x;
			var dy : Number = _y - p.y;
			return Math.sqrt(dx * dx + dy * dy);
		}

		public function clone(dx : Number = 0, dy : Number = 0) : Point2D {
			return new Point2D(_x + dx, _y + dy);
		}

		override public function toString() : String {
			return "[Point2D (x : " + Math.round(_x * 100) / 100 + " y : " + Math.round(_y * 100) / 100 + ")]";
		}
	}
}
